package com.team06.dao;
import com.team06.pojo.Airl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AirlDao {
    private static final Logger LOGGER = LoggerFactory.getLogger(AirlDao.class.getName());
    private final JdbcTemplate jdbcTemplate;

    public AirlDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insertMessage(Airl entity) {
        String sql = "INSERT INTO MSG_DFME_AIRL (" +
                "SENDER, RECEIVER, SEQUENCE, DTIME, MTYPE, STYPE, " +
                "DFLT_FLID, DFLT_FIDE, DFLT_FFID, AIRL_ARPT_ID) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        try {
            jdbcTemplate.update(sql,
                    entity.getSender(),
                    entity.getReceiver(),
                    entity.getSequence(),
                    entity.getDtime(),
                    entity.getMtype(),
                    entity.getStype(),
                    entity.getDfltFlid(),
                    entity.getDfltFide(),
                    entity.getDfltFfid(),
                    entity.getAirlArptId()
            );
            LOGGER.info("数据插入成功（通过 Spring JDBC）");
        } catch (Exception e) {
            LOGGER.error("Failed to insert message into database", e);
            throw new RuntimeException("Failed to insert message into database", e);
        }
    }
}